package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Slf4j
@Api(tags = "护理计划")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 分页查询护理计划
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> selectPage(@ApiParam(value = "护理计划名称") String name,
                                                                  @ApiParam(value = "护理计划状态") Integer status,
                                                                  @ApiParam(value = "分页页码")@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                  @ApiParam(value = "每页显示记录数")@RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.selectPage(name,status,pageNum,pageSize);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param nursingPlanDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增项目")
    public ResponseResult add(@ApiParam(value = "护理计划数据传输对象", required = true)@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    /**
     * 根据Id查询回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据Id查询护理计划")
    public ResponseResult<NursingPlanVo> getById(@ApiParam(value ="Id")@PathVariable Integer id){
        NursingPlanVo nursingPlanVo=nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    /**
     * 根据Id修改 如果不用根据Id修改的话 需要修改前端的代码:待完成
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("根据Id修改护理计划")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto,@PathVariable Integer id){
        nursingPlanService.update(nursingPlanDto,id);
        return success();
    }

    /**
     * 根据Id删除
     * 这里的DeleteMapping不能写成("/{id}") 要写成("{id}")
     * 这个疑问保留 一直以来没有注意过这个问题
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据Id删除护理计划")
    public ResponseResult delete(@ApiParam(value ="id")@PathVariable Integer id){
        nursingPlanService.delete(id);
        return success();
    }

    /**
     * 启用或者新增
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用或者禁用护理计划")
    public ResponseResult startOrStop(@ApiParam(value ="Id")@PathVariable Integer id,
                                      @ApiParam(value ="status")@PathVariable Integer status){
        nursingPlanService.startOrStop(id,status);
        return success();
    }

    /**
     * 查询所有的护理计划
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有的护理计划")
    public ResponseResult<List<NursingPlanVo>> getAllPlan(){
        List<NursingPlanVo> list= nursingPlanService.getAllPlan();
        return success(list);
    }
}
